const App = getApp();
const navigationBarHeight = (getApp().diygwstatusBarHeight + 44) + 'px'
Page({
    data: {
        msgs1:[],
        cmemo: '',

    },

    //弹出提示信息
    showModal(message) {
        App.WxService.showModal({
            title: '友情提示',
            content: message,
            showCancel: !1,
        });
    },
    onShareAppMessage: function() {},

    //页面加载
    onLoad(option) {
        if (option) {
            this.setData({
                globalOption: option
            })
        }
    },

    //页面显示
    onShow() {
        this.getMsgs1();

    },

    //页面跳转
    navigateTo(e) {
        App.navigateTo(e.currentTarget.dataset.url, e.currentTarget.dataset);
    },
    
     //获取数据
     getMsgs1() {
         //设置要传递的参数
        let param = {
            f: 1,
            mid: wx.getStorageSync("mid"),
            loadmsg: `正在加载中`
        };

        App.HttpService.getData(param, "/board_List").then(data => {  //执行服务器Servlet
            this.setData({
                msgs1: data  //把从服务器端得到的值赋值给数组
            });
        });
    },

    //得到留言框输入的值
    getInputValue(e) {
        this.setData({
            cmemo: e.detail.value
        })
    },

    //留言
    liuyan(e) {
        var that = this;
        if (this.data.cmemo == "") {
            this.showModal("反馈内容不能为空");
        } else {

            //设置要传递的参数
            let param = {
                mid: wx.getStorageSync('mid'),
                memo: this.data.cmemo,
                loadmsg: `正在加载中`
            };

            App.HttpService.saveData(param, "/board_Add").then(data => { //执行服务器Servlet
                App.WxService.showToast({
                    title: "提交成功!",
                    icon: 'success',
                    duration: 1000,
                });
                setTimeout(function () {
                    that.getMsgs1();
                    that.setData({
                        cmemo: ''
                    })
                }, 1000)
            });
        }


    },

    //删除
    delData1(e) {
        const dataset = e.currentTarget.dataset;

         //设置要传递的参数
        let param = {
            id: dataset.id,
            f: 1
        };
        App.WxService.showModal({
            title: '友情提示',
            content: '确定要删除吗？',
        }).then(data => {
            if (data.confirm == 1) {
                App.HttpService.delData(param, "/board_Delete").then(data => { //执行服务器Servlet
                    this.getMsgs1(); //获取数据
                });
            }
        })
    },

})